package com.yonyou.pmclouds.workflow.service;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.service.rmiitf.IProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import yonyou.bpm.rest.BaseService;
import yonyou.bpm.rest.BpmRest;

/**
 *  云审批服务工厂类
 *  @author zhangzhonghao
 */

@Component
public class ProcessServiceFactory {

    public static final String FORM_SERVICE = "formService";

    public static final String REPOSITORY_SERVICE = "repositoryService";

    public static final String IDENTITY_SERVICE = "identityService";

    public static final String RUNTIME_SERVICE = "runtimeService";

    public static final String TASK_SERVICE = "taskService";

    public static final String HISTORY_SERVICE = "historyService";

    private static IProcessService processService;

    public static Object getProcessService(String serviceType, String userId, String tenantId) throws BusinessException {
        BpmRest bpmRest = processService.bpmRestServices(userId, tenantId);
        BaseService baseService = null;
        switch (serviceType){
            case FORM_SERVICE :
                baseService = bpmRest.getFormService(); break;
            case REPOSITORY_SERVICE :
                baseService = bpmRest.getRepositoryService(); break;
            case IDENTITY_SERVICE :
                baseService = bpmRest.getIdentityService(); break;
            case RUNTIME_SERVICE :
                baseService = bpmRest.getRuntimeService(); break;
            case TASK_SERVICE :
                baseService = bpmRest.getTaskService(); break;
            case HISTORY_SERVICE :
                baseService = bpmRest.getHistoryService(); break;

        }
        return baseService;
    }

    @Autowired
    public void setProcessService(IProcessService processService) {
        ProcessServiceFactory.processService = processService;
    }
}
